
import logging
from google.appengine.ext import db

class Player(db.Model):
    uid = db.StringProperty()
    name = db.StringProperty()
    photoUrl = db.StringProperty()
    password = db.StringProperty()
    
class Deck(db.Model):
    name = db.StringProperty()
    content = db.TextProperty()
    player = db.ReferenceProperty(Player)
    rank = db.IntegerProperty(default=0)

class DBLayer:
    @staticmethod
    def decklist(p):
        result = db.GqlQuery("SELECT * FROM Deck where player = :1",p)
        return result
    
    @staticmethod
    def loadDeck(name,player):
        result = db.GqlQuery("SELECT * FROM Deck WHERE name = :1 AND player = :2",name,player)
        return result.get()
    
    @staticmethod
    def saveDeck(name,content,player):
        deck = Deck(name,content,player)
        deck.put()
        return
        
    @staticmethod
    def removeDeck(uid):
        result = db.GqlQuery("DELETE * FROM Playlog WHERE uid  = :1",uid)
        return result
        
    @staticmethod
    def getPlayer(uid):
        result = db.GqlQuery("SELECT * FROM Player WHERE uid = :1",uid)
        return result.get()